<template>
    <div class="box">
      <el-row class="row-tr">
        <el-col :md="12" class="row-td">
          <div >
            <el-input v-model="input" placeholder="请输入内容" @blur="imageUpdate"></el-input>
            <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </el-col>
        <el-col :md="12" class="row-td">
          <el-input  v-model="input" placeholder="请输入内容" @blur="imageUpdate"></el-input>
        </el-col>
      </el-row>
      <el-row class="row-tr">
        <el-col :md="12" class="row-td">
          <el-input  v-model="input" placeholder="请输入内容" @blur="imageUpdate"></el-input>
        </el-col>
        <el-col :md="12" class="row-td">
          <el-input  v-model="input" placeholder="请输入内容" @blur="imageUpdate"></el-input>
        </el-col>
      </el-row>
    </div>
</template>

<script>
  export default {
    name: 'detail',
    data() {
      return {
        input: '',
        imageUrl: ''
      }
    },
    methods: {
      imageUpdate() {
        this.imageUrl = this.input
      },
      handleAvatarSuccess(res, file) {
        console.log('handleAvatarSuccess')
        this.imageUrl = URL.createObjectURL(file.raw)
        console.log(this.imageUrl)
      },
      beforeAvatarUpload(file) {
        console.log('beforeAvatarUpload')
      }
    }
  }
</script>

<style scoped>
  .row-tr{
    margin: 0.5rem 0;
  }

  .row-td{
    margin: 0.6rem 0;
    /*padding: 0.5rem 0;*/
  }

  .avatar-uploader >>> .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader >>> .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
